package com.mediacloud.app.newsmodule.fragment;

import static com.mediacloud.app.nav2.fragment.HqyNavFragmentKt.FLAG_SCROLL_POSITION;
import static com.mediacloud.app.nav2.fragment.HqyNavFragmentKt.FLAG_SCROLL_TOP;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Rect;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseIntArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;

import com.eventTrack.CDPTrackReportManager;
import com.eventTrack.TXReportManager;
import com.mediacloud.app.appfactory.cache.AppConfig;
import com.mediacloud.app.assembly.clickutils.NoDoubleClickUtils;
import com.mediacloud.app.assembly.util.FunKt;
import com.mediacloud.app.assembly.util.Utility;
import com.mediacloud.app.assembly.views.XRefreashListView.IXListViewListener;
import com.mediacloud.app.fbnavsk.SecondFloorHandlerKt;
import com.mediacloud.app.fbnavsk.SecondNav;
import com.mediacloud.app.model.SmartRecommendEvent;
import com.mediacloud.app.model.adaptor.BaseAdaptor;
import com.mediacloud.app.model.component.ComponentItem;
import com.mediacloud.app.model.interfaces.DataInvokeCallBack;
import com.mediacloud.app.model.interfaces.InterfaceLayout;
import com.mediacloud.app.model.interfaces.LBSNavigate;
import com.mediacloud.app.model.news.ArticleItem;
import com.mediacloud.app.model.news.ArticleListData;
import com.mediacloud.app.model.news.BaseMessageReciver;
import com.mediacloud.app.model.news.CMSFieldStyle;
import com.mediacloud.app.model.news.CatalogItem;
import com.mediacloud.app.model.news.kt.TypeX;
import com.mediacloud.app.model.view.floatwin.FloatButtonGroup;
import com.mediacloud.app.nav2.fragment.HqyNavFragment;
import com.mediacloud.app.newsmodule.BuildConfig;
import com.mediacloud.app.newsmodule.R;
import com.mediacloud.app.newsmodule.activity.NavigateActivity;
import com.mediacloud.app.newsmodule.adaptor.NewsListItemBaseAdaptor;
import com.mediacloud.app.newsmodule.adaptor.NewsListItemStyleAdaptor;
import com.mediacloud.app.newsmodule.adaptor.basenews.IAdapterRefresh;
import com.mediacloud.app.newsmodule.adaptor.bigimg_nosliceline.BigImageListAdaptor;
import com.mediacloud.app.newsmodule.adaptor.bigimg_nosliceline.BigImageNoSliceLineAdaptor;
import com.mediacloud.app.newsmodule.adaptor.component.BufferComponentContainer;
import com.mediacloud.app.newsmodule.adaptor.component.ComponentHolder;
import com.mediacloud.app.newsmodule.adaptor.component.IExposure;
import com.mediacloud.app.newsmodule.adaptor.component.ScrollExposure;
import com.mediacloud.app.newsmodule.adaptor.microlive.MicroLiveListAdapter;
import com.mediacloud.app.newsmodule.fragment.newslist.CMSNewsListWidthBannerFragment;
import com.mediacloud.app.newsmodule.fragment.newslist.ListDividerLayerUtilKt;
import com.mediacloud.app.newsmodule.fragment.video.vod.PlayClickListener;
import com.mediacloud.app.newsmodule.fragment.video.vod.VideoListPlayerUtil;
import com.mediacloud.app.newsmodule.fragment.video.vod.VideoNewsListFragment;
import com.mediacloud.app.newsmodule.utils.BindEventBus;
import com.mediacloud.app.newsmodule.utils.CacheDataKt;
import com.mediacloud.app.newsmodule.utils.ContentListCache;
import com.mediacloud.app.newsmodule.utils.LBSChooseListener;
import com.mediacloud.app.newsmodule.utils.LBSRefreshLocation;
import com.mediacloud.app.newsmodule.utils.NewsItemClickUtils;
import com.mediacloud.app.newsmodule.utils.NewsListDataInvoker;
import com.mediacloud.app.newsmodule.utils.TabLayoutColorKt;
import com.mediacloud.app.newsmodule.utils.ViewVisiblePercentToolKt;

import com.mediacloud.app.newsmodule.view.LocationChooseHeader;
import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig;
import com.mediacloud.app.reslib.enums.Navigate;
import com.mediacloud.app.reslib.enums.StyleOther;
import com.mediacloud.app.reslib.enums.ToolBarActionF5OrTop;
import com.mediacloud.app.reslib.enums.XKey;
import com.mediacloud.app.view.XSmartRefreshLayout;
import com.outsource.factory.IOutsourceFactory;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import com.tencent.mmkv.MMKV;
import com.utils.ExposurePoolService;
import com.utils.SystemServiceManager;


import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 新闻内容列表页 不带banner
 */
@SuppressWarnings("ALL")
public class BaseNewsListFragment extends HqyNavFragment implements ToolBarActionF5OrTop, IOutsourceFactory,
        InterfaceLayout, IXListViewListener, OnItemClickListener, LBSNavigate, OnRefreshLoadMoreListener {
    public ListView mCatalogContentItemListView;
    protected TextView emptyTipsText;
    @SuppressWarnings("rawtypes")
    protected BaseAdaptor adaptor;
    protected String catalogID;
    protected int pageNum = 1;
    protected int pageSize = 20;
    protected boolean isLoading = false;
    protected boolean attached = false;
    protected final String SaveAdaptor = "SaveAdaptor";
    protected CatalogItem catalogItem;
    protected NewsListDataInvoker dataInvoker;
    protected BaseDataInvokeCallBack dataCallback;
    protected BufferComponentContainer bufferComponentContainer;
    protected LinearLayout headerViewContainer;
    String titleName = "";
    /**
     * 组件的
     */
    // protected ComponentContainer componetContainer;
    protected boolean haveBanner = false;
    protected boolean haveAddComponent31 = false;
    protected boolean haveAddComponent36 = false;

    protected XSmartRefreshLayout mXSmartRefreshLayout;
    protected View sohuHeaderView;

    /**
     * 是否是智能推荐导航
     */
    protected boolean isSmartRecommend = false;
    /**
     * 上一次滚动停留的位置
     */
    protected int lastSelectedPosition;
    /**
     * 上一次滚动位置的偏差
     */
    protected int lastSelectedPositionOffset = 0;
    /**
     * 以这个作为一瓶显示数据的标记位，超过这个值就认为滚过了一屏
     */
    private int visibleItemCount = -1;
    /**
     * 第一屏最后一个元素显示在listView中显示的部分
     */
    private int firstPageLastItemOffset = 0;

    private SparseIntArray sparseArrayListViewItemHeight = new SparseIntArray();

    protected ContentListCache<Object> contentListCache = new ContentListCache<>(null);
    protected boolean isAddFooterEmptyArticleItem = false;

    //记录推荐组件的数据，获取request_id和model_id
    protected ArticleListData mArticleListData;

    boolean hideFlag = true;
    boolean showFlag = true;

    float instanceX = 0f;

    protected boolean needCache() {
        return true;
    }

    protected Class<? extends BaseDataInvokeCallBack<? extends BaseMessageReciver>> getDataInvokeCallBackClass() {
        return BaseNewsDataInvokeCallBack.class;
    }

    @SuppressWarnings("unchecked")
    private void initCallBackInstance() {
        Class<?> classRef = getDataInvokeCallBackClass();
        try {
            dataCallback = (BaseDataInvokeCallBack<? extends BaseMessageReciver>) classRef.getConstructors()[0].newInstance(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void initDataInvoker() {
        dataInvoker = new NewsListDataInvoker(dataCallback);
    }

    protected AbsListView.OnScrollListener onScrollListener;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        contentListCache.setPageSize(pageSize);
        String TAG = getClass().getCanonicalName();
        //Log.i(TAG, "onCreate fmg");
        headerViewContainer = new LinearLayout(getActivity());
        headerViewContainer.setOrientation(LinearLayout.VERTICAL);
//        componetContainer = new ComponentContainer(getActivity(), getCurrentICMP26Holder());
//        componetContainer.componentListItemStyleAdaptor.catalogItem = catalogItem;
        bufferComponentContainer = new BufferComponentContainer(requireContext());
        bufferComponentContainer.setPlayClickListener(playClickListener);
        headerViewContainer.addView(bufferComponentContainer);
        initCallBackInstance();
        initDataInvoker();
    }

    private int begin_position = 0;
    private int stop_position = 0;
    protected int visiblePosition = 0;
    protected int firstPosition = 0;
    public int curPosition = -1;
    int mNetType;
    int lastVisibleItemPosition = 0;
    //private ObjectAnimator translationX;
    private boolean flag = false;
    private int mLastRecordScrollY = 0;

    @SuppressWarnings({"unchecked", "rawtypes"})
    @Override
    public void initView() {
        attached = false;
        isLoading = false;
        pageNum = 1;
        loadingView = findViewById(R.id.mLoadingView);
        initStateView();
        showStateView(TYPE_LOADING, false);
        mXSmartRefreshLayout = mRootView.findViewById(R.id.mXSmartRefreshLayout);
        mCatalogContentItemListView = Utility.findViewById(mRootView, R.id.mCatalogContentItemListView);
        mCatalogContentItemListView.setFriction(ViewConfiguration.getScrollFriction() * 2.5F);
        mCatalogContentItemListView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

            @Override
            public boolean onPreDraw() {
                mCatalogContentItemListView.getViewTreeObserver().removeOnPreDrawListener(this);

                if (mCatalogContentItemListView.getChildCount() == 0)
                    return true;
                int firstPosition = mCatalogContentItemListView.getFirstVisiblePosition();
                View view = mCatalogContentItemListView.getChildAt(firstPosition);
                while (view != null && (view.getHeight() == 0 || view.getVisibility() == View.GONE)) {
                    firstPosition++;
                    view = mCatalogContentItemListView.getChildAt(firstPosition);
                    if (firstPosition >= mCatalogContentItemListView.getChildCount()) {
                        break;
                    }
                }
                View firstVisibleView = mCatalogContentItemListView.getChildAt(mCatalogContentItemListView.getFirstVisiblePosition());
                if (firstVisibleView == null) {
                    return true;
                }
                final int firstTop = firstVisibleView.getTop();
                final int lastBottom = mCatalogContentItemListView.getChildAt(mCatalogContentItemListView.getChildCount() - 1).getBottom();
                //当前显示内容的高度
                int totalHeight = lastBottom - firstTop;
                //计算出第一屏的高度
                visibleItemCount = mCatalogContentItemListView.getLastVisiblePosition();
                int listViewHeight = mCatalogContentItemListView.getHeight();
                if (totalHeight > listViewHeight) {//在这个情况下最后的一个元素没有显示完
                    View lastView = mCatalogContentItemListView.getChildAt(visibleItemCount);
                    if (lastView != null) {
                        while (visibleItemCount >= 0 && (lastView.getHeight() == 0 || lastView.getVisibility() == View.GONE)) {
                            visibleItemCount--;
                            lastView = mCatalogContentItemListView.getChildAt(visibleItemCount);
                        }
                        //计算最后一个元素的显示部分
                        firstPageLastItemOffset = lastView.getHeight() - (lastView.getBottom() - listViewHeight);
                    }
//                    if (lastView != null)
//                        Log.w(TAG, this + "  onPreDraw visibleItemCount :  " + visibleItemCount + " firstPageLastItemOffset : " + firstPageLastItemOffset + "  listViewHeight: " + listViewHeight +
//                                " lastView.getTop() :: " + lastView.getTop() + "  lastViewHeight :: "
//                                + lastView.getHeight() + " getSelectedItemPosition: " + mCatalogContentItemListView.getSelectedItemPosition() + " totalHeight : " + totalHeight);
                }
                return true;
            }
        });
        // translationX = ObjectAnimator.ofFloat(floatButtonGroup, "translationX", 0f, 300f);
        onScrollListener = new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                setScrollerState(scrollState);
                if (AbsListView.OnScrollListener.SCROLL_STATE_IDLE == scrollState) {
                    if (scrollOverFirstPage() && !hasScrollerFlag(FLAG_SCROLL_POSITION)) {
                        setScrollerFlag(FLAG_SCROLL_POSITION);
                    } else if (!scrollOverFirstPage() && !hasScrollerFlag(FLAG_SCROLL_TOP)) {
                        setScrollerFlag(FLAG_SCROLL_TOP);
                    }
                    //  stop_position = Math.abs(getListViewScrollY());
                    if (catalogItem != null) {
                        app_jhapp_home_subtab_content_imp();
//                        ReportManager.getInstance().scroll_page(String.valueOf(begin_position),
//                                String.valueOf(stop_position), MD5Utils.getMD5String(catalogItem.getName()), catalogItem.getName());
//                        begin_position = stop_position;
                    }
                }
                //判断ListView是否滑动到第一个Item的顶部
                if (mXSmartRefreshLayout != null && mCatalogContentItemListView.getChildCount() > 0 && mCatalogContentItemListView.getFirstVisiblePosition() == 0
                        && mCatalogContentItemListView.getChildAt(0).getTop() >= mCatalogContentItemListView.getPaddingTop()) {
                    //解决滑动冲突，当滑动到第一个item，下拉刷新才起作用
                    mXSmartRefreshLayout.setEnableRefresh(true);
                } else {
                    mXSmartRefreshLayout.setEnableRefresh(false);
                }
                if (scrollState == ListView.OVER_SCROLL_IF_CONTENT_SCROLLS) {
                    if (flag) {
                        return;
                    }
                    if (NoDoubleClickUtils.scrollRepeatOut()) {
                        return;
                    }
                    flag = true;
//                    translationX = ObjectAnimator.ofFloat(floatButtonGroup, "translationX", 0f, 300f);
//                    translationX.setDuration(600);
//                    translationX.start();
                }
                try {
                    //滑动停止后，
                    if (scrollState == ListView.OVER_SCROLL_ALWAYS) {


                        if (!hadChoosed) {
                            return;
                        }
                        flag = false;
//                        if (FloatButtonGroup.animatorFlag){
//                            if (translationX != null) {
//                                translationX.cancel();
//                            }
//                            if (translationX2 != null) {
//                                translationX2.start();
//                            }
//                        }

                        boolean isAutoPlay = MMKV.defaultMMKV().decodeBool(XKey.AUTO_PLAY, false);
                        if (!isAutoPlay) {
//                            Log.e("auto", "isAutoPlay: " + !isAutoPlay);
                            return;
                        }

                        int yPs = 0;//有地址选择的时候出现问题，加一个修正值
                        if (catalogItem != null && catalogItem.getLbsItem() != null) {
                            yPs = 1;
                        }
                        lastVisibleItemPosition = firstPosition == 0 ? 0 : firstPosition;
                        //是否自动播放

                        //是否wifi
                        if (checkNetType()) {
                            if (mNetType != ConnectivityManager.TYPE_WIFI) {
                                //Log.e("auto", "not wifi");
                                return;
                            }
                        }
                        View itemView = null;
                        ArticleItem mArticleItem = null;
                        for (int i = 0; i < visiblePosition; i++) {
                            View tempItemView = mCatalogContentItemListView.getChildAt(i);
                            if (tempItemView != null && (tempItemView.getTop() >= 0 &&
                                    ViewVisiblePercentToolKt.isFloatEquals(ViewVisiblePercentToolKt.getViewVisiblePercent(tempItemView), 1f))) {
                                //处理越界崩溃
                                int tempPosition = firstPosition + i - 1 - yPs;
//                                if (tempPosition>=0&&tempPosition<adaptor.getListContentData().size()) {
//                                    Log.e("auto", "tempItemView--top:" + tempItemView.getTop() + "----bottom:" + tempItemView.getBottom() +
//                                            "---viewHeight:" + tempItemView.getHeight() + "---firstPosition:" + firstPosition +"----visiblePosition:"+visiblePosition+
//                                            "---tempPosition:" + tempPosition + "---title:" + ((ArticleItem) adaptor.getListContentData().get(tempPosition)).getTitle());
//                                }
                                if (curPosition == tempPosition && tempPosition != -1) {
                                    return;
                                }
                                if ((tempPosition < 0) || (tempPosition >= adaptor.getListContentData().size())) {
                                    //Log.e("auto", "over size ");
                                    continue;
                                }
                                ArticleItem mTempArticleItem = (ArticleItem) adaptor.getListContentData().get(tempPosition);

                                if (mTempArticleItem.getType() == TypeX.NEWS.VIDEO) {
                                    if ((BaseNewsListFragment.this instanceof VideoNewsListFragment) &&
                                            (catalogItem != null && catalogItem.getCatalogStyle() == 2)) {
                                        curPosition = tempPosition;
                                        //Log.e("auto", "curPosition: " + curPosition);
                                        itemView = tempItemView;
                                        mArticleItem = mTempArticleItem;
                                        break;
                                    } else if (mTempArticleItem.getCmsCustomStyle() != null && mTempArticleItem.getCmsCustomStyle().getType() != CMSFieldStyle.None) {
                                        if (mTempArticleItem.getCmsCustomStyle().getType() == CMSFieldStyle.BigImage16_9) {
                                            curPosition = tempPosition;
                                            mArticleItem = mTempArticleItem;
                                            //Log.e("auto", "curPosition: " + curPosition);
                                            itemView = tempItemView;
                                            break;
                                        }

                                    }
                                } else {
                                    //Log.e("auto", "not video");
                                }

                            }
                        }
                        if (mArticleItem == null || TextUtils.isEmpty(mArticleItem.getVideo()) || mArticleItem.getVideo().equals("{}")) {
                            //Log.e("auto", "not have video path");
                            return;
                        }
                        if (!hadChoosed) {
                            return;
                        }
                        if ((BaseNewsListFragment.this instanceof VideoNewsListFragment) &&
                                (catalogItem != null && catalogItem.getCatalogStyle() == 2)) {
                            if (itemView == null) {
                                return;
                            }
                            View videoLayout = itemView.findViewById(R.id.shipindatuyangshi);
                            if (videoLayout != null) {
//                                ViewGroup iconLayout = videoLayout.findViewById(R.id.iconLayout);
                                View logo = videoLayout.findViewById(R.id.logo);
                                logo.performClick();
//                                onPlayIcoClick(videoLayout, iconLayout, videoPlayView, mArticleItem);
                            }
                        } else if (mArticleItem.getCmsCustomStyle() != null &&
                                mArticleItem.getCmsCustomStyle().getType() != CMSFieldStyle.None) {
                            if (mArticleItem.getCmsCustomStyle().getType() == CMSFieldStyle.BigImage16_9) {
                                if (itemView == null) {
                                    return;
                                }
                                View videoLayout = itemView.findViewById(R.id.bigImgAndSpiderStyle);
                                if (videoLayout != null) {
//                                ViewGroup iconLayout = videoLayout.findViewById(R.id.iconLayout);
                                    View itemIcon = videoLayout.findViewById(R.id.itemIcon);
                                    itemIcon.performClick();
//                                onPlayIcoClick(videoLayout, iconLayout, videoPlayView, mArticleItem);
                                }
                            }
//                            else if (mArticleItem.getCmsCustomStyle().getType() == CMSFieldStyle.BigImgMode
//                            ||mArticleItem.getCmsCustomStyle().getType() == CMSFieldStyle.BigImage1_1) {
//                                View videoLayout = itemView.findViewById(R.id.bigImgStyle);
//                                if (videoLayout!=null) {
////                                ViewGroup iconLayout = videoLayout.findViewById(R.id.iconLayout);
//                                    View itemIcon = videoLayout.findViewById(R.id.itemIcon);
//                                    itemIcon.performClick();
////                                onPlayIcoClick(videoLayout, iconLayout, itemIcon, mArticleItem);
//                                }
//                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }


            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                View firstVisibleView = mCatalogContentItemListView.getChildAt(firstVisibleItem);
                if (firstVisibleView != null) {
                    sparseArrayListViewItemHeight.put(firstVisibleItem, firstVisibleView.getHeight());
                }
                visiblePosition = visibleItemCount;
                firstPosition = firstVisibleItem;

                int listChildCount = mCatalogContentItemListView.getChildCount();
                for (int y = 0; y < listChildCount; y++) {
                    View itemView = mCatalogContentItemListView.getChildAt(y);

                    if (itemView instanceof LinearLayout) {
                        int childCount = bufferComponentContainer.getContainer().getChildCount();
                        for (int i = 0; i < childCount; i++) {
                            View child = bufferComponentContainer.getContainer().getChildAt(i);
                            if (TXReportManager.getVisibility(child)) {
                                Object tag = child.getTag();
                                if (tag != null) {
                                    if (tag instanceof ScrollExposure) {
                                        Rect rect = new Rect();
                                        bufferComponentContainer.getLocalVisibleRect(rect);
                                        View ai_people = child.findViewById(R.id.ai_people);
                                        ObjectAnimator objectAnimatorX = null;
                                        if ((rect.top - 150) > child.getTop() || (rect.bottom + 150) < child.getBottom()) {
                                            instanceX = ai_people.getX();
                                            if (instanceX >= 0 && hideFlag) {
                                                hideFlag = false;
                                                showFlag = true;
                                                objectAnimatorX = ObjectAnimator.ofFloat(ai_people, "translationX", -(Utility.dpToPx(getContext(), 170)));
                                                objectAnimatorX.setDuration(1000);
                                                objectAnimatorX.start();
                                            }
                                        } else {
                                            instanceX = ai_people.getX();
                                            if (instanceX < 0 && showFlag) {
                                                hideFlag = true;
                                                showFlag = false;
                                                objectAnimatorX = ObjectAnimator.ofFloat(ai_people, "translationX", Utility.dpToPx(getContext(), 170));
                                                objectAnimatorX.setDuration(1000);
                                                objectAnimatorX.addListener(new Animator.AnimatorListener() {
                                                    @Override
                                                    public void onAnimationStart(Animator animator) {
                                                    }

                                                    @Override
                                                    public void onAnimationEnd(Animator animator) {
                                                        ((ScrollExposure) tag).startAnimation();
                                                    }

                                                    @Override
                                                    public void onAnimationCancel(Animator animator) {
                                                    }

                                                    @Override
                                                    public void onAnimationRepeat(Animator animator) {
                                                    }
                                                });
                                                objectAnimatorX.start();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }


                }
            }
        };
        mCatalogContentItemListView.setOnScrollListener(onScrollListener);
        if (adaptor == null) {
            NewsListItemStyleAdaptor newsAdapter = new NewsListItemStyleAdaptor(getActivity(), playClickListener);
            newsAdapter.listView = mCatalogContentItemListView;
            adaptor = newsAdapter;
        }
        if (getFragmentArguments() != null) {
            saveInstanceArguments = getFragmentArguments();
            catalogID = saveInstanceArguments.getString("id");
            catalogItem = saveInstanceArguments.getParcelable("catalog");
        } else if (saveInstanceArguments != null) {
            catalogID = saveInstanceArguments.getString("id");
            catalogItem = saveInstanceArguments.getParcelable("catalog");
        }
        if (TextUtils.isEmpty(catalogID)) {
            catalogID = "";
        }
//        if (componetContainer != null) {
//            componetContainer.componentListItemStyleAdaptor.catalogItem = catalogItem;
//        }
        setNid(catalogID);
        //如果有其他样式的 就用这个列表样式了
        if (catalogItem != null && catalogItem.getCatalogStyle() == StyleOther.OtherStyle)//&&catalogItem.getStyleOther()!=null)
        {
            if (adaptor instanceof NewsListItemStyleAdaptor) {
                ((NewsListItemStyleAdaptor) adaptor).destroy();
            }
            adaptor = new BigImageNoSliceLineAdaptor(getActivity(), catalogItem, playClickListener);
        } else if (catalogItem != null && catalogItem.getCatalogStyle() == StyleOther.DEFAULT_BIG_IMAGE)//&&catalogItem.getStyleOther()!=null)
        {
            if (adaptor instanceof NewsListItemStyleAdaptor) {
                ((NewsListItemStyleAdaptor) adaptor).destroy();
            }
            adaptor = new BigImageListAdaptor(getActivity(), catalogItem, playClickListener);
        }
        addLBSChosoeHeader();
        if (getNavigate() != null && getNavigate().getSpecial_effect() == 1) {
            sohuHeaderView = LayoutInflater.from(getActivity()).inflate(R.layout.sohu_top_sign, null, false);
            mCatalogContentItemListView.addHeaderView(sohuHeaderView);
        }
        //  mCatalogContentItemListView.addHeaderView(headerViewContainer);
        mCatalogContentItemListView.addHeaderView(headerViewContainer);
        mCatalogContentItemListView.setHeaderDividersEnabled(false);
        if (adaptor instanceof NewsListItemStyleAdaptor) {
            try {
                ((NewsListItemBaseAdaptor) adaptor).catalogItem = catalogItem;
            } catch (Exception e) {
                e.printStackTrace();
                //Log.w(TAG, "" + e.getMessage());
            }
        }
        if (!TextUtils.isEmpty(catalogID)) {
            contentListCache.setCatalogId(catalogID);
        }
        mCatalogContentItemListView.setFooterDividersEnabled(false);
        mCatalogContentItemListView.setAdapter(adaptor);
        mXSmartRefreshLayout.setEnableLoadMore(true);
        mXSmartRefreshLayout.setEnableRefresh(true);
        mXSmartRefreshLayout.setOnRefreshLoadMoreListener(this);
        mCatalogContentItemListView.setOnItemClickListener(this);
        if (retryTips != null) {
            retryTips.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!currentState.equals(TYPE_LOADING)) {
                        showStateView(TYPE_LOADING, false);
                        onRefresh();
                    }
                }
            });
        }
//        componetContainer.setmListView(this.mCatalogContentItemListView);
//        componetContainer.setRootView(mRootView);
        setRefreshLayoutColor(mXSmartRefreshLayout, getNavigate());
        beforeUserCache();
        new BindEventBus(this, adaptor);
    }

    private boolean checkNetType() {
        ConnectivityManager cm = SystemServiceManager.getConnectivityManager(getContext());
        NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isAvailable()) {
            mNetType = networkInfo.getType();
            return true;
        }
        return false;
    }

    public int getScrollY() {
        View c = mCatalogContentItemListView.getChildAt(0);
        if (c == null) {
            return 0;
        }
        int firstVisiblePosition = mCatalogContentItemListView.getFirstVisiblePosition();
        int top = c.getTop();
        return -top + firstVisiblePosition * c.getHeight();
    }

    @Override
    protected void initOther() {
        super.initOther();
//        if (getActivity() != null && !checkInited) {
//            useCache();
//        }
    }

    public void beforeUserCache() {

    }

    /**
     * listView是不是滚动超过第一屏的距离
     *
     * @return true 超过了第一屏的距离
     */
    private boolean scrollOverFirstPage() {

        return getListViewScrollY() > mCatalogContentItemListView.getHeight();
//        if(mCatalogContentItemListView.getFirstVisiblePosition() > visibleItemCount){
//            return true;
//        }
//        if(mCatalogContentItemListView.getFirstVisiblePosition() < visibleItemCount){
//            return false;
//        }
//        View firstVisibleView = mCatalogContentItemListView.getChildAt(visibleItemCount);
//        if(firstVisibleView != null){
//            if(firstPageLastItemOffset > 0){//原来内容没有显示完
//                int topOffset = firstVisibleView.getTop();//这个值只能是0或者负值
//                Log.w(TAG,"topOffset :: "+topOffset+"  firstVisibleView "+firstVisibleView.getHeight()+" firstPageLastItemOffset  "+firstPageLastItemOffset+ "  scroll height "+mCatalogContentItemListView.getHeight());
//                //当topOffset绝对值大于firstPageLastItemOffset说明超过一屏
//                return Math.abs(topOffset) > firstPageLastItemOffset ;
//            }else {
//                return false;
//            }
//        }
//        return false;
    }

    private int getListViewScrollY() {
        int firstVisiblePosition = mCatalogContentItemListView.getFirstVisiblePosition();
        int listViewScrollY = 0;
        for (int i = 0; i < firstVisiblePosition; i++) {
            listViewScrollY += sparseArrayListViewItemHeight.get(i, 0);
        }
        //添加第一个可见元素的高度
        View firstVisibleView = mCatalogContentItemListView.getChildAt(0);
        if (firstVisibleView != null) {
            listViewScrollY += -firstVisibleView.getTop();
        }
        return listViewScrollY;
    }


    @CallSuper
    @Override
    public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mCatalogContentItemListView.setVerticalScrollBarEnabled(false);
        mCatalogContentItemListView.setHeaderDividersEnabled(false);
        mCatalogContentItemListView.setFooterDividersEnabled(false);
        mCatalogContentItemListView.setDividerHeight(view.getContext().getResources().getDimensionPixelOffset(R.dimen.dimen1));
        //  mCatalogContentItemListView.setSelector(R.color.transparent);
        if (hadChoosed) {
            SecondFloorHandlerKt.initFStyle(this, mXSmartRefreshLayout, sohuHeaderView);
        } else {
            SecondFloorHandlerKt.navPaddingTopMatch(this);
        }

        //变态的写法 先这样吧  用于向上遍历获取是否是时间轴导航的 不想改其他 感觉会有问题
        mCatalogContentItemListView.setTag(R.id.isFromTimeLineNav, false);
        //时间线导航 配置过样式才设置
        if (catalogItem != null && catalogItem.getCatalogStyle() != StyleOther.OtherStyle && AppFactoryGlobalConfig.FeatureModule.BigModule.TimeLineNav.equals(catalogItem.getCatalog_type()) && getNavigate() != null && getNavigate().getFont_selected() != null) {
            // mCatalogContentItemListView.setTag(R.id.timeLineColor, Nav2ParserKt.parseSelectedTxtColor(getNavigate(), view.getContext()));
            mCatalogContentItemListView.setTag(R.id.timeLineColor, ContextCompat.getColor(requireContext(), R.color.text_cctv7_red));
            mCatalogContentItemListView.setTag(R.id.isFromTimeLineNav, true);
            mCatalogContentItemListView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
                @Override
                public boolean onPreDraw() {
                    mCatalogContentItemListView.getViewTreeObserver().removeOnPreDrawListener(this);
                    int listWidth = mCatalogContentItemListView.getMeasuredWidth() - mCatalogContentItemListView.getPaddingStart() - mCatalogContentItemListView.getPaddingEnd();
                    if (listWidth <= 0) {
                        return true;
                    }
                    mCatalogContentItemListView.setDivider(ListDividerLayerUtilKt.generateDividerDrawable(view.getContext(), listWidth, TabLayoutColorKt.getTabLayoutStateColor(view.getContext(), getNavigate().getSecond_navigate()).second));
                    mCatalogContentItemListView.setDividerHeight(view.getContext().getResources().getDimensionPixelOffset(R.dimen.dimen2));
                    return true;
                }
            });
        }
    }

    @org.jetbrains.annotations.Nullable
    @Override
    public Navigate getNavigate() {
        if (catalogItem != null && catalogItem.getNavigate() != null)
            return catalogItem.getNavigate();
        return super.getNavigate();
    }

    protected void addLBSChosoeHeader() {
        //LBS栏目不为空就加上头
        if (catalogItem != null && catalogItem.getLbsItem() != null) {
            int maxLBSH = getActivity().getResources().getDimensionPixelSize(R.dimen.dime_fifty);
            LocationChooseHeader locationChooseHeader = new LocationChooseHeader(getActivity());
            locationChooseHeader.catalogItem = catalogItem;
            locationChooseHeader.tag = FGTag.TagID;
//			mCatalogContentItemListView.addSecondHeader(maxLBSH,locationChooseHeader);
            locationChooseHeader.setVisiableHeight(maxLBSH);
            mCatalogContentItemListView.addHeaderView(locationChooseHeader);
        }
    }


    @Override
    public void onDestroyView() {
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
        if (mVideoListPlayerUtil != null) {
            mVideoListPlayerUtil.onDestroy();
            mVideoListPlayerUtil = null;
        }
        if (playClickListener != null) {
            playClickListener = null;
        }
        //    LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
        if (dataInvoker != null) {
            dataInvoker.destory();
            dataInvoker = null;
        }
        if (adaptor != null) {
            if (adaptor instanceof NewsListItemStyleAdaptor) {
                ((NewsListItemStyleAdaptor) adaptor).destroy();
            }
            if (adaptor instanceof BigImageNoSliceLineAdaptor) {
                ((BigImageNoSliceLineAdaptor) adaptor).destroy();
            }
            if (adaptor.getListContentData() != null) {
                adaptor.getListContentData().clear();
            }
        }
        if (mCatalogContentItemListView != null) {
            mCatalogContentItemListView.setOnItemClickListener(null);
        }
        attached = false;
//        if (componetContainer != null)
//            componetContainer.dispose();
//        componetContainer = null;
        isFirst = true;
        if (mVideoListPlayerUtil != null)
            mVideoListPlayerUtil.onDestroy();
        dataCallback = null;
        super.onDestroyView();
    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
                            long id) {
        if (FunKt.isFastClick()) {
            int index = position;
            index = index - mCatalogContentItemListView.getHeaderViewsCount();
            if (index < 0)
                return;
            ArticleItem item = (ArticleItem) adaptor.getItem(index);
            item.setParentId(catalogID);
            item.setPositionInList(index);
            TextView titleView = view.findViewById(R.id.newsTitle);
            TextView newsVRTitle = view.findViewById(R.id.newsVRTitle);
            TextView zhiding = view.findViewById(R.id.text_title);//置顶组件
            TextView cmsTitle = view.findViewById(R.id.tv_title_v2);//cms样式
            TextView videoTitle = view.findViewById(R.id.titleTv);//视频导航
            TextView bigImgTitle = view.findViewById(R.id.itemTitle);//大图无分割线
            if (titleView != null) titleView.setTextColor(Color.parseColor("#666666"));
            if (newsVRTitle != null) newsVRTitle.setTextColor(Color.parseColor("#666666"));
            if (zhiding != null) zhiding.setTextColor(Color.parseColor("#666666"));
            if (cmsTitle != null) cmsTitle.setTextColor(Color.parseColor("#666666"));
            if (videoTitle != null) videoTitle.setTextColor(Color.parseColor("#666666"));
            if (bigImgTitle != null) bigImgTitle.setTextColor(Color.parseColor("#666666"));
            NewsItemClickUtils.OpenItemNewsHandle(getActivity(), item.getType(), item, catalogItem);
            CDPTrackReportManager.getInstance().NewsRPClick(position,item,null);
            checkReport(item,position);


        }
    }

    /**
     * 二级导航内容互动事件,可以理解为通过组件的更多点进去之后的独立页面里面进行的点击事件
     * 我们在这里通过父activity来判断是否位于二级页面
     */
    private void checkReport(ArticleItem item,int position) {
        if (getActivity() instanceof NavigateActivity) {
            TXReportManager txReportManager = TXReportManager.getInstance();

        }
        TXReportManager txReportManager = TXReportManager.getInstance();
        if ("电台".equals(TXReportManager.getInstance().getSecondName()) && TXReportManager.getInstance().isMoreListPage()) {
            TXReportManager.getInstance().app_jhapp_radio_more_content_interact(item, catalogItem.getName());
        }

        /*if (txReportManager.getFirstTabInfo().getTabName().equals("首页") && txReportManager.getCurrentNavigate().getTabName().endsWith("详情页")) {
            txReportManager.app_jhapp_home_subtab_more_content_interact("查看详情", item);
        } else if (txReportManager.getFirstTabInfo().getTabName().equals("首页") && txReportManager.getCurrentNavigate().getTabName().equals("智库") && txReportManager.getThirdTabInfo().getTabName() != null) {
            txReportManager.app_jhapp_home_subtab_more_content_interact("查看详情", item);
        }*/
       else if (TXReportManager.getInstance().getFirstTabInfo().getTabName().equals("首页")) {
            txReportManager.app_jhapp_home_subtab_more_content_interact("点击查看详情", item);
        }
         else {
            TXReportManager.getInstance().app_jhapp_home_subtab_content_interact(
                    "查看详情",
                    catalogItem.getName(),
                    catalogItem.getName(),
                    "",
                    "",
                    "",
                    "",
                    "",
                    item);
        }
            txReportManager.app_jhapp_explore_service_interact("点击查看", item, item.getPositionInList(), catalogItem.getName());
    }

    public VideoListPlayerUtil mVideoListPlayerUtil;

    public PlayClickListener playClickListener = new PlayClickListener() {
        @Override
        public void onPlayIcoClick(View rootView, ViewGroup container, View playIcon, final ArticleItem item) {

            if (mVideoListPlayerUtil == null) {
                mVideoListPlayerUtil = new VideoListPlayerUtil(getActivity(), mCatalogContentItemListView, BaseNewsListFragment.this);
                mVideoListPlayerUtil.setHqyNavFragment(BaseNewsListFragment.this);

                if (getParentFragment() instanceof SecondNav) {
                    mVideoListPlayerUtil.mPlayer.setViewPlayer(((SecondNav) getParentFragment()).getViewPager());
                }
            }
            if (item != null && mVideoListPlayerUtil.item != null && mVideoListPlayerUtil.getPlayer() != null
                    && mVideoListPlayerUtil.item.equals(item) && mVideoListPlayerUtil.getPlayer().isPlaying()) {
                return;
            }
            mVideoListPlayerUtil.setPlayerContainer(rootView, container, playIcon, !TextUtils.isEmpty(item.getGoodsID()), new OnClickListener() {
                @Override
                public void onClick(View v) {
                    item.setParentId(catalogID);
                    NewsItemClickUtils.OpenItemNewsHandle(getActivity(), item.getType(), item, catalogItem);
                }
            }, item);
            if (item.getType() == TypeX.NEWS.MICRO_DYNAMIC)
                mVideoListPlayerUtil.isAutoPlayVideo = true;
            else mVideoListPlayerUtil.isAutoPlayVideo = false;
            mVideoListPlayerUtil.setVideoDetail(catalogID + "", item);
        }
    };


    @Override
    public int getLayoutResID() {
        return R.layout.fragment_catalog_itemcontent;
    }

    @SuppressWarnings("rawtypes")
    public void setAdaptor(BaseAdaptor adaptor) {
        this.adaptor = adaptor;
    }


    boolean checkInited = false;

    @Override
    public final void onRefresh() {
        if (getActivity() == null)
            return;
        attached = true;
        checkInited = true;
        AppConfig appConfig = new AppConfig(getActivity());
        boolean unkeep = appConfig.lbsIsAutoMode() && Utility.gpsIsOpen(getActivity());
        if (catalogItem != null && catalogItem.getLbsItem() != null && !isFirst && unkeep) {
            new LBSRefreshLocation(this).start(getActivity());
        } else {
            isFirst = false;
            doRefresh();
        }
    }

    boolean isFirst = true;

    @CallSuper
    public void doRefresh() {
        if (isLoading)
            return;
        contentListCache.clear();
        isLoading = true;
        pageNum = 1;
//        if (componetContainer != null) {
//            componetContainer.stopWindows();
//            componetContainer.stopUpSmallVideoUi();
//        }
        //Log.w("APPTAG", "onFresh");
        hideFlag = true;
        showFlag = true;
        getNewsListData();
    }

    private void useCache() {
        contentListCache.clear();
        if (this instanceof CMSNewsListWidthBannerFragment) {
            showStateView(TYPE_LOADING, false);
            onRefresh();
        } else {
            ArticleListData dataResult = null;
            if (!TextUtils.isEmpty(catalogID)) {
                dataResult = CacheDataKt.readData(this, catalogID, ArticleListData.class);
            }
            if (adaptor != null && dataCallback != null && dataResult != null && (dataResult.articleList.size() > 0 || dataResult.componentItems.size() > 0)) {
                //Log.w("APPTAG", "useCache");
                showStateView(TYPE_LOADING, false);
                dataCallback.success(dataResult);
            } else {
                showStateView(TYPE_LOADING, false);
                onRefresh();
            }
        }
    }


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        //  registerMulti();
    }

    @Override
    public void onPause() {

        super.onPause();
        if (mVideoListPlayerUtil != null) {
            mVideoListPlayerUtil.addViewHistory();
        }
//        if (componetContainer != null && componetContainer.mMultiVideoPlayer != null) {
//
//            if (MultiVideoMannager.getInstace().isHandPause) {
//            } else {
//                componetContainer.mMultiVideoPlayer.onPause();
//            }
//        }
    }

    @Override
    public void onResume() {

        curPosition = -1;
        visiblePosition = 0;
        firstPosition = 0;
//        if (componetContainer != null && componetContainer.mMultiVideoPlayer != null) {
//            if (MultiVideoMannager.getInstace().isHandPause) {
//
//            } else {
//                componetContainer.mMultiVideoPlayer.onStart();
//            }
//        }
        if (emptyTipsText == null) {
            emptyTipsText = Utility.findViewById(mRootView, R.id.emptyTipsText);
        }
        super.onResume();
    }

//
//    private void registerMulti() {
//
//        IntentFilter filter = new IntentFilter();
//        filter.addAction(MultiUtils.outFullbord);
//        filter.addAction(MultiUtils.closeThe);
//
//        LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, filter);
//    }
//
//    BroadcastReceiver mReceiver = new BroadcastReceiver() {
//        @Override
//        public void onReceive(Context context, Intent intent) {
//
//            String action = intent.getAction();
//            Log.i("test", "mReceiver action:" + action);
//            if (action != null) {
//                if (componetContainer != null && componetContainer.mMultiVideoPlayer != null) {
//
//                    if (action.equals(MultiUtils.outFullbord)) {
//                        componetContainer.mMultiVideoPlayer.outFullScreen();
//                    } else if (action.equals(MultiUtils.closeThe)) {
//                        stopThePlayer();
//                        isExcode = false;
//                    }
//                }
//
//
//            }
//
//
//        }
//    };


    @CallSuper
    @Override
    public void unChosoed() {
        super.unChosoed();
        if (mVideoListPlayerUtil != null) {
            mVideoListPlayerUtil.stopPlay();
        }
        //      stopThePlayer();
    }

    boolean isVisible = false;
    boolean isExcode = false;
//
//    private void stopThePlayer() {
//        if (componetContainer != null && !isExcode) {
//            componetContainer.stopWindows();
//            //componetContainer.mMultiVideoPlayer.stopPlay();
//            componetContainer.stopUpSmallVideoUi();
//            isExcode = true;
//        }
//        MultiVideoMannager.getInstace().isHiden = true;
//
//    }

    @CallSuper
    @Override
    public void choosed() {
        super.choosed();
        if (getActivity() != null) {
            mRootView.post(() -> {
                SecondFloorHandlerKt.initFStyle(BaseNewsListFragment.this, mXSmartRefreshLayout, sohuHeaderView);
            });
        }
        isExcode = false;
        if (isAdded()) {
            app_jhapp_home_subtab_content_imp();
        }
    }

    public void initToRefresh() {
        if (getActivity() == null || requireActivity().isFinishing() || requireActivity().isDestroyed()) {
            return;
        }
        if (ExtendKt.getSearchId() != null) {//从搜索跳过来直接加载，不走缓存
            showStateView(TYPE_LOADING, false);
            doRefresh();
        } else
            useCache();
    }

    protected void showBottomDivide() {
        Fragment fragment = getRootFragment();
        if (fragment instanceof SecondNav) {
            SecondNav secondNav = (SecondNav) fragment;
            try {
                //1 2 代表新浪和搜狐的二楼效果 参考的SecondFloorHandler.kt
                if (getNavigate() != null &&
                        (getNavigate().getSpecial_effect() == 1 || getNavigate().getSpecial_effect() == 2)
                        && secondNav.getSecondTabIsNotOnToolBar()) {
                    secondNav.setTableBottomDivideVisible(false);
                } else {
                    secondNav.setTableBottomDivideVisible(true);
                }
            } catch (Exception e) {
                e.printStackTrace();
                secondNav.setTableBottomDivideVisible(true);
            }
        }
    }

    @CallSuper
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        //Log.i("test", "player:setUserVisibleHint");
        if (getUserVisibleHint()) {
            isVisible = true;
            //   isExcode=false;
            //Log.i("test", "player:hiden?:visible");
        } else {

            //Log.i("test", "player:hiden?:GONE");
            if (mVideoListPlayerUtil != null) {
                mVideoListPlayerUtil.stopPlay();
            }

            // isVisible = false;
        }
        curPosition = -1;
        visiblePosition = 0;
        firstPosition = 0;
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        //Log.i("test", "player:onHiddenChanged:" + hidden);
        curPosition = -1;
        visiblePosition = 0;
        firstPosition = 0;
        if (hidden) {
            if (mVideoListPlayerUtil != null) {
                mVideoListPlayerUtil.stopPlay();
            }
//            if (componetContainer != null) {
//                componetContainer.stopWindows();
//                componetContainer.stopUpSmallVideoUi();
//            }
//            MultiVideoMannager.getInstace().isHiden = true;
        } else {

        }
    }


    /**
     * 取新闻列表
     */
    protected void getNewsListData() {
        matchLBSCataglogId();
        if (dataInvoker != null && catalogID != null)
            if (ExtendKt.getSearchId() != null) {//来自顶部搜索点击的条目
                Map<String, String> params = new HashMap<>();
                params.put("only_article", "1");
                params.put("catid_cover", ExtendKt.getSearchId());
                dataInvoker.getContentListWithAd(catalogID, pageNum, pageSize, params);
            } else
                dataInvoker.getContentListWithAd(catalogID, pageNum, pageSize, null);
    }

    protected final void matchLBSCataglogId() {
        if (catalogItem != null && !TextUtils.isEmpty(catalogItem.getLbsNavigateDataId())) {
            catalogID = catalogItem.getLbsNavigateDataId();
            contentListCache.setCatalogId(catalogID);
        }
    }

    @Override
    public void onLoadMore() {
        if (isLoading)
            return;
        if (!(this instanceof CMSNewsListWidthBannerFragment)) {
            //如果那边已经预加载了下一页的数据
            if (contentListCache.getCache2().containsKey(pageNum + 1)) {
                ArticleListData dataResult = contentListCache.getCache2().get(pageNum + 1);
                if (dataCallback != null && dataResult != null && dataResult.articleList.size() > 0) {
                    pageNum++;
                    isLoading = true;
                    dataCallback.success(dataResult);
                    return;
                }
            }
        }
        pageNum++;
        isLoading = true;
        loadmore();
    }

    public void loadmore() {
        getNewsListData();
    }

    boolean chooseLocationVisible = false;

    @Override
    public void setChooseLocationVisible(boolean value) {
        chooseLocationVisible = value;
    }

    @Override
    public boolean getChooseLocationVisible() {
        return chooseLocationVisible;
    }

    @NotNull
    @Override
    public View getInterceptView() {
        return mCatalogContentItemListView;
    }

    @Override
    public final void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        onLoadMore();
    }

    @Override
    public final void onRefresh(@NonNull RefreshLayout refreshLayout) {
        onRefresh();
    }

    @Override
    public final void f5() {
        if (getScrollerState()) {
            mCatalogContentItemListView.smoothScrollToPosition(0);
        } else {
            mCatalogContentItemListView.setSelection(0);
        }
        mXSmartRefreshLayout.setEnableRefresh(true);
        mXSmartRefreshLayout.autoRefresh(200);
    }

    @Override
    public final void gun() {
        //这里也会滚动到顶部，处理一下滚动状态
        setScrollParams();
        setScrollerFlag(FLAG_SCROLL_TOP);
        mCatalogContentItemListView.setSelection(0);
    }

    @Override
    public boolean handleScroller() {
        if (hasScrollerFlag(FLAG_SCROLL_TOP)) {
            setScrollerFlag(FLAG_SCROLL_POSITION);
            mCatalogContentItemListView.setSelectionFromTop(lastSelectedPosition, lastSelectedPositionOffset);
            return true;
        }
        if (hasScrollerFlag(FLAG_SCROLL_POSITION)) {
            setScrollParams();
            setScrollerFlag(FLAG_SCROLL_TOP);
            mXSmartRefreshLayout.getRefreshKernel().moveSpinner(0, false);
            mCatalogContentItemListView.requestFocusFromTouch();
            mCatalogContentItemListView.setSelection(0);
            return true;
        }
        return true;
    }

    private void setScrollParams() {
        lastSelectedPosition = mCatalogContentItemListView.getFirstVisiblePosition();
        View view = mCatalogContentItemListView.getChildAt(0);
        if (view != null) {
            lastSelectedPositionOffset = view.getTop();
        }
    }


  /*  protected LiveNavCall liveNavCall;

    public void setLiveCall(LiveNavCall call) {
        liveNavCall = call;
    }*/

    protected boolean needUpdateComponent = true;

    public class BaseNewsDataInvokeCallBack extends BaseDataInvokeCallBack<ArticleListData> {

        @SuppressWarnings("unchecked")
        public void success(ArticleListData result) {
            if (getActivity() == null || requireActivity().isFinishing() || requireActivity().isDestroyed()) {
                return;
            }

            //活动查询成功，上报
            if (catalogID == "1332" || catalogID == "1958") {
                TXReportManager.getInstance().activity_query();
            }

            if (catalogID.equals("24") || BaseNewsListFragment.this instanceof CMSNewsListWidthBannerFragment) {
                mArticleListData = result;
            }

            boolean isCacheData = false;
            if (ExtendKt.getSearchId() == null) //搜索页面不存数据
                if (needCache() && pageNum == 1) {
                    //不是上次的缓存数据才进行缓存
                    isCacheData = result.orginData.optInt("is_cache", 0) == 1;
                    if (!isCacheData) {
                        try {
                            result.orginData.put("is_cache", 1);
                            CacheDataKt.saveData(BaseNewsListFragment.this, catalogID, result.orginData + "");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
//            if (liveNavCall != null)
//                liveNavCall.success(result);
            if (adaptor == null)
                return;
            isLoading = false;
//            mCatalogContentItemListView.setPullLoadEnable(result.more);
            JSONObject data = result.orginData.optJSONObject("data");
            if (pageNum == 1) {
                curPosition = -1;
                visiblePosition = 0;
                firstPosition = 0;
                if (FloatButtonGroup.haveFloatField(data)) {
                    initFloatWin(data);
                } else {
                    hideFloatWin();
                }
            }
            if (pageNum == 1 && !result.haveMore() &&
                    result.articleList != null && result.articleList.size() != 0
                && !(adaptor instanceof MicroLiveListAdapter)) {
                ArticleItem footerEmptyArticleItem = new ArticleItem();
                footerEmptyArticleItem.setType(TypeX.CUSTOM.Footer_Empty);
                result.articleList.add(footerEmptyArticleItem);
                isAddFooterEmptyArticleItem = true;
            }

            if (pageNum == 1) {
                if (adaptor instanceof IAdapterRefresh) {
                    ((IAdapterRefresh) adaptor).refresh();
                }
                if (adaptor.getListContentData() != null && !isSmartRecommend) {
                    adaptor.getListContentData().clear();
                }

                //添加组件  用的HeadView
                if (needUpdateComponent) {
                    //  componetContainer.updateComponent(result.componentItems);
                    for (int i = 0; i < result.componentItems.size(); i++) {
                        result.componentItems.get(i).belongNavId = catalogID;
                    }
                    bufferComponentContainer.setData(result.componentItems, catalogItem);
                }
            }

            mXSmartRefreshLayout.finishLoadMore();
            mXSmartRefreshLayout.setNoMoreData(!result.haveMore());
            if (catalogID.equals("24") || BaseNewsListFragment.this instanceof CMSNewsListWidthBannerFragment) {
                if (result.articleList.isEmpty()) {
                    mXSmartRefreshLayout.setNoMoreData(true);
                } else {
                    mXSmartRefreshLayout.setNoMoreData(false);
                }
            }
            ListPreLoadTool.preLoad(requireContext(), result.articleList);
            if (adaptor.getListContentData() == null) {
                adaptor.setListContentData(result.articleList);
            } else {
                if (isSmartRecommend && pageNum == 1) {
                    List<ArticleItem> listContentData = adaptor.getListContentData();
                    for (int i = 0; i < listContentData.size(); i++) {
                        if (listContentData.get(i).getType() == TypeX.CUSTOM.SMART_RECOMMENT_REFRESH) {
                            adaptor.getListContentData().remove(i);
                            break;
                        }
                    }
                    mXSmartRefreshLayout.setHeaderText("智能引擎为您发现" + result.articleList.size() + "条数据");
                    ArticleItem articleItem = new ArticleItem();
                    articleItem.setType(TypeX.CUSTOM.SMART_RECOMMENT_REFRESH);
                    result.articleList.add(articleItem);
                    adaptor.getListContentData().addAll(0, result.articleList);
                } else {
                    adaptor.getListContentData().addAll(result.articleList);
                }
            }
            adaptor.notifyDataSetChanged();
            mXSmartRefreshLayout.finishRefresh();

            if (isAddFooterEmptyArticleItem) {
                if (needUpdateComponent && (adaptor.getListContentData() == null || adaptor.getListContentData().size() == 0) && result.componentItems.size() == 0) {
                    showStateView(TYPE_NO_CONTENT, false);
                } else {
                    closeStateView();
                }
            } else {
                if (needUpdateComponent && (adaptor.getListContentData() == null || adaptor.getListContentData().size() == 0) && result.componentItems.size() == 0) {
                    showStateView(TYPE_NO_CONTENT, false);
                } else {
                    closeStateView();
                }
            }

            if (isCacheData) {
                mXSmartRefreshLayout.autoRefresh(500);
            }
            if (!isCacheData) {
                dataReady = true;
                if (hadChoosed) {
                    app_jhapp_home_subtab_content_imp();
                }
                if (catalogID.equals("24") || BaseNewsListFragment.this instanceof CMSNewsListWidthBannerFragment) {
                    return;
                }
                contentListCache.setPageNum(pageNum + 1);
                contentListCache.preload2();
            }

        }
    }

    public abstract class BaseDataInvokeCallBack<T extends BaseMessageReciver> implements DataInvokeCallBack<T> {
        @Override
        public void fault(Object object) {
            if (getActivity() == null || requireActivity().isFinishing() || requireActivity().isDestroyed()) {
                return;
            }
            //Log.w("APPTAG", "fault" + object);
//            if (liveNavCall != null)
//                liveNavCall.fault();
            isLoading = false;
            pageNum--;
//            mCatalogContentItemListView.stopLoadMore();
//            mCatalogContentItemListView.stopRefresh();
            mXSmartRefreshLayout.finishRefresh(false);
            mXSmartRefreshLayout.finishLoadMore();
            if (object != null && adaptor != null && (adaptor.getListContentData() == null
                    || adaptor.getListContentData().size() == 0)) {
                showStateView(TYPE_NET_NOT_GIVE_FORCE, false);
            } else if (adaptor != null && (adaptor.getListContentData() == null
                    || adaptor.getListContentData().size() == 0)) {
                showStateView(TYPE_NO_CONTENT, false);
            } else
                closeStateView();
        }
    }

    public void onSaveInstanceState(Bundle outState) {
        outState.putString("id", catalogID);
        outState.putParcelable("catalog", catalogItem);
        super.onSaveInstanceState(outState);
    }

    @CallSuper
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == LBSChooseListener.Request && resultCode == Activity.RESULT_OK)
            LBSChooseListener.getInstance().onActivityResult(data, this);
    }


    protected boolean dataReady = false;
    //点击首页二级板块内合集类内容且内容列表曝光时（只上报用户停止滑动且呈现在屏幕上1秒以上的内容，滚动过程中的数据无需上报）
    private Runnable app_jhapp_home_subtab_content_impRunable = new Runnable() {
        @Override
        public void run() {
            ExposurePoolService.getExecutorService().execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        int listChildCount = mCatalogContentItemListView.getChildCount();
                        for (int y = 0; y < listChildCount; y++) {
                            View itemView = mCatalogContentItemListView.getChildAt(y);
                            if (itemView instanceof LinearLayout) {
                                int childCount = bufferComponentContainer.getContainer().getChildCount();
                                for (int i = 0; i < childCount; i++) {
                                    View view = bufferComponentContainer.getContainer().getChildAt(i);
                                    //判断View可见了才采集数据
                                    if (TXReportManager.getVisibility(view)) {
                                        Object tag = null;
                                        List<ComponentItem> list = bufferComponentContainer.getAdapter().getListContentData();
                                        try {
                                            //因为ComponentListItemStyleAdaptor 里 判断了 C99993 是这样设置的tag,咱也不敢改啊,只有这样去写
                                            if (list.get(i).getWidget() == TypeX.COMPONENT.C99993) {
                                                tag = view.getTag(R.id.component3_viewholder);
                                            } else {
                                                tag = view.getTag();
                                            }
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                        if (tag != null) {
                                            if (tag instanceof IExposure) {
                                                List<ArticleItem> articleItemList = ((IExposure) tag).getExposureArticles();
                                                if (articleItemList != null) {
                                                    ComponentItem componentItem = ((IExposure) tag).getExposureComponentItem();
                                                    String componentTitle = "";
                                                    if (componentItem != null) {
                                                        if (!TextUtils.isEmpty(componentItem.getTitle())){
                                                        componentTitle = componentItem.getTitle();
                                                        }
                                                        if (TextUtils.isEmpty(componentTitle)){
                                                            if (TextUtils.isEmpty(componentItem.getSname())){
                                                                if (!TextUtils.isEmpty(componentItem.getName())){
                                                                componentTitle = componentItem.getName();
                                                                }
                                                            }else {
                                                                componentTitle = componentItem.getSname();
                                                            }
                                                        }
                                                    }
                                                    for (int k = 0; k < articleItemList.size(); k++) {
                                                        ArticleItem article = articleItemList.get(k);
                                                        article.setPositionInList(k);
                                                        checkReport2(article, componentTitle, itemView, i,componentItem);
                                                    }
                                                }
                                            } else {
                                                if (tag instanceof ComponentHolder) {
                                                    //这里是 还没实现IExposure的组件先不管了。遇到了在加
                                                    if (BuildConfig.DEBUG) {
                                                        Log.w("XYADDD", "未实现IExposure " + tag.getClass().getSimpleName());
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            } else {
                                //这里先取一下组件3的tag
                                Object tag = itemView.getTag(R.id.component3_viewholder);
                                if (tag == null) {
                                    tag = itemView.getTag();
                                }
                                if (tag != null) {
                                    if (tag instanceof IExposure) {
                                        List<ArticleItem> articleItemList = ((IExposure) tag).getExposureArticles();
                                        ComponentItem componentItem = ((IExposure) tag).getExposureComponentItem();
                                        String componentTitle = "";
                                        if (componentItem != null) {
                                            if (!TextUtils.isEmpty(componentItem.getTitle())){
                                                componentTitle = componentItem.getTitle();
                                            }
                                            if (TextUtils.isEmpty(componentTitle)){
                                                if (TextUtils.isEmpty(componentItem.getSname())){
                                                    if (!TextUtils.isEmpty(componentItem.getName())){
                                                        componentTitle = componentItem.getName();
                                                    }
                                                }else {
                                                    componentTitle = componentItem.getSname();
                                                }
                                            }
                                        }
                                        if (TextUtils.isEmpty(componentTitle)) {
                                            if (!TextUtils.isEmpty(catalogItem.getName())){
                                                titleName = catalogItem.getName();
                                            }
                                        } else {
                                            titleName = componentTitle;
                                        }
                                        if (articleItemList != null) {
                                            for (int k = 0; k < articleItemList.size(); k++) {
                                                ArticleItem article = articleItemList.get(k);
                                                article.setPositionInList(k);
                                                if ("电台".equals(TXReportManager.getInstance().getSecondName()) && TXReportManager.getInstance().isMoreListPage()) {
                                                    TXReportManager.getInstance().app_jhapp_radio_more_content_imp(article, titleName);
                                                }
                                                if ("电台".equals(TXReportManager.getInstance().getCurrentChannelInfo().getTabName())){
                                                    TXReportManager.getInstance().app_jhapp_radio_content_imp(article,titleName);
                                                }
                                                //CDPTrackReportManager.getInstance().NewsRPExpose(k,article);
                                                TXReportManager.getInstance().app_jhapp_home_subtab_content_imp(article, componentItem, catalogItem);
                                                TXReportManager.getInstance().app_jhapp_explore_service_cntnt_imp(article, k, titleName);
                                                if (TXReportManager.getInstance().getFirstTabInfo().getTabName().equals("军媒")) {
                                                    if ("杂志".equals(TXReportManager.getInstance().getCurrentChannelInfo().getTabName())) {
                                                        TXReportManager.getInstance().app_jhapp_magazine_imp(article);
                                                    }
                                                }
                                            }
                                        }
                                    } else {
                                        if (tag instanceof ComponentHolder) {
                                            //这里是 还没实现IExposure的组件先不管了。遇到了在加
                                            if (BuildConfig.DEBUG) {
                                                Log.w("XYADDD", "未实现IExposure " + tag.getClass().getSimpleName());
                                            }
                                        } else {
                                            //这里是列表数据
                                            listMeta(itemView);
                                        }
                                    }
                                } else {
                                    //这里是列表数据
                                    listMeta(itemView);
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }

    };

    private void checkReport2(ArticleItem article, String componentTitle, View itemView, int i,ComponentItem componentItem) {
        if (TextUtils.isEmpty(componentTitle)) {
            if (!TextUtils.isEmpty(catalogItem.getName())){
                titleName = catalogItem.getName();
            }
        } else {
            titleName = componentTitle;
        }
        if ("电台".equals(TXReportManager.getInstance().getSecondName()) && TXReportManager.getInstance().isMoreListPage()) {
            TXReportManager.getInstance().app_jhapp_radio_more_content_imp(article, titleName);
        }
        if ("电台".equals(TXReportManager.getInstance().getCurrentChannelInfo().getTabName())){
            TXReportManager.getInstance().app_jhapp_radio_content_imp(article,titleName);
        }
       // CDPTrackReportManager.getInstance().NewsRPExpose(i,article);
        TXReportManager.getInstance().app_jhapp_home_subtab_content_imp(article, componentItem, catalogItem);
            TXReportManager.getInstance().app_jhapp_explore_service_cntnt_imp(article, i, titleName);
            if (TXReportManager.getInstance().getFirstTabInfo().getTabName().equals("军媒")) {
            if ("杂志".equals(TXReportManager.getInstance().getCurrentChannelInfo().getTabName())) {
//                    TXReportManager.getInstance().app_jhapp_magazine_imp(article);
            }
        } else if (TXReportManager.getInstance().getFirstTabInfo().getTabName().equals("首页") && !TextUtils.isEmpty(TXReportManager.getInstance().getMoreTitle())) {
            TXReportManager.getInstance().app_jhapp_home_subtab_more_content_imp(article);
        } else if (TXReportManager.getInstance().getFirstTabInfo().getTabName().equals("视频")) {
            TXReportManager.getInstance().app_jhapp_video_imp(componentTitle, article, i);
        }

    }

    private void listMeta(View itemView) {
        try {
            titleName = catalogItem.getName();
            int articlePosition = mCatalogContentItemListView.getPositionForView(itemView);
            ArticleItem articleItem = (ArticleItem) adaptor.getListContentData().get(articlePosition - mCatalogContentItemListView.getHeaderViewsCount());
            articleItem.setPositionInList(articlePosition - mCatalogContentItemListView.getHeaderViewsCount());
            if ("电台".equals(TXReportManager.getInstance().getSecondName()) && TXReportManager.getInstance().isMoreListPage()) {
                TXReportManager.getInstance().app_jhapp_radio_more_content_imp(articleItem, titleName);
            }
            if ("电台".equals(TXReportManager.getInstance().getCurrentChannelInfo().getTabName())){
                TXReportManager.getInstance().app_jhapp_radio_content_imp(articleItem,titleName);
            }
            CDPTrackReportManager.getInstance().NewsRPExpose(articlePosition,articleItem,null);
            TXReportManager.getInstance().app_jhapp_home_subtab_content_imp(articleItem, null, catalogItem);
                TXReportManager.getInstance().app_jhapp_explore_service_cntnt_imp(articleItem, articlePosition, titleName);
            if (TXReportManager.getInstance().getFirstTabInfo().getTabName().equals("军媒")) {
                if ("杂志".equals(TXReportManager.getInstance().getCurrentChannelInfo().getTabName())) {
                    TXReportManager.getInstance().app_jhapp_magazine_imp(articleItem);
                } else if ("电台".equals(TXReportManager.getInstance().getCurrentChannelInfo().getTabName())) {
                    if (TXReportManager.getInstance().getCurrentNavigate().getTabName() != null) {
                        if (TXReportManager.getInstance().getCurrentNavigate().getTabName().endsWith("详情页")) {
                            TXReportManager.getInstance().app_jhapp_home_subtab_more_content_imp(articleItem);
                        }
                    }
                }

            }  else if (TXReportManager.getInstance().getFirstTabInfo().getTabName().equals("首页") && !TextUtils.isEmpty(TXReportManager.getInstance().getMoreTitle())) {
                TXReportManager.getInstance().app_jhapp_home_subtab_more_content_imp(articleItem);
            }else {
                if ("视频".equals(TXReportManager.getInstance().getFirstTabInfo().getTabName())) {
                    TXReportManager.getInstance().app_jhapp_video_imp(catalogItem.getName(), articleItem, articlePosition);
                }
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void app_jhapp_home_subtab_content_imp() {
        if (!dataReady) return;
        if (mCatalogContentItemListView != null) {
            mCatalogContentItemListView.removeCallbacks(app_jhapp_home_subtab_content_impRunable);
            mCatalogContentItemListView.postDelayed(app_jhapp_home_subtab_content_impRunable, TXReportManager.EXPOSURE_DELAY);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onRefreshData(SmartRecommendEvent recommendEvent) {
        f5();
    }
}